package com.atguigu.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        servlet1.处理编码2.获取请求参数3.处理业务逻辑 4.响应客户端
//        重定向地址不加/ 转发的加/
        request.setCharacterEncoding("UTF-8");
       //取请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //验证
        if ("tom".equals(username) && "123456".equals(password)) {
            //成功
            response.sendRedirect("success.html");
        } else {
            //失败
            request.getRequestDispatcher("/login.html").forward(request,response);
        }

    }
}
